﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Application_erabliere.Classes_de_données
{
   public class facture
   {

       #region Propriété

       private int m_ID;

       public int ID
       {
           get { return m_ID; }
       }

       private int m_IDCommande;

       public int IDCommande
       {
           get { return m_IDCommande; }
       }

       private DateTime m_DateCreation;

       public DateTime DateCreation
       {
           get { return m_DateCreation; }
       }

       private DateTime m_DatePaiementComplet;

       public DateTime DatePaiementComplet
       {
           get { return m_DatePaiementComplet; }
           set { m_DatePaiementComplet = value; }
       }

       private string m_Commentaire;

       public string Commentaire
       {
           get { return m_Commentaire; }
           set { m_Commentaire = value; }
       }

       #endregion

       #region Constructeur

       public facture()
       {
           m_Commentaire = null;
           m_DateCreation = new DateTime();
           m_DatePaiementComplet = new DateTime();
           m_ID = -1;
           m_IDCommande = -1;
           //ne pas oublier liste de produit
       }

       public facture(int pIDCommande, string pCommentaire)
       {
           m_Commentaire = pCommentaire;
           m_IDCommande = pIDCommande;
           m_DateCreation = DateTime.Now;
           m_DatePaiementComplet = new DateTime(0, 0, 0, 0, 0, 0);
            //ne pas oublier liste de produit
       }

       public facture(int pIDCommande, string pCommentaire, DateTime pDateCreation)
       {
           m_IDCommande = pIDCommande;
           m_DateCreation = pDateCreation;
           m_Commentaire = pCommentaire;
           m_DatePaiementComplet = new DateTime(0, 0, 0, 0, 0, 0);
           //ne pas oublier liste de produit
       }

   #endregion

       #region Méthode

       public static facture RechercherParID(int pId)
       {
           facture objfacture = new facture();
           List<object[]> objlsttab = Utilitaires.Commandehelper.RequeteSQL("select * from factures where ID=" + pId + ";");

           try
           {
               objfacture.m_DatePaiementComplet = DateTime.Parse(objlsttab[0][3].ToString()); 
           }
           catch 
           {

               objfacture.m_DatePaiementComplet = new DateTime(0, 0, 0, 0, 0, 0);
           }

           try
           {
               objfacture.m_Commentaire = objlsttab[0][4].ToString();
           }
           catch 
           {

               objfacture.m_Commentaire = string.Empty;
           }
           
           objfacture.m_ID = (int)objlsttab[0][0];
           objfacture.m_IDCommande = (int)objlsttab[0][1];
           objfacture.m_DateCreation = DateTime.Parse(objlsttab[0][2].ToString());
           objfacture.m_DatePaiementComplet = DateTime.Parse(objlsttab[0][3].ToString());
           objfacture.m_Commentaire = objlsttab[0][4].ToString();
           return objfacture;
       }

       public static facture RechercherParClient(string pClient)
       {
           facture objfacture = new facture();
           List<object[]> objlsttab = Utilitaires.Commandehelper.RequeteSQL("select * from facture where client = " + pClient + ";");


           try
           {
               objfacture.m_DatePaiementComplet = DateTime.Parse(objlsttab[0][3].ToString());
           }
           catch
           {

               objfacture.m_DatePaiementComplet = new DateTime(0, 0, 0, 0, 0, 0);
           }

           try
           {
               objfacture.m_Commentaire = objlsttab[0][4].ToString();
           }
           catch
           {

               objfacture.m_Commentaire = string.Empty;
           }

           objfacture.m_ID = (int)objlsttab[0][0];
           objfacture.m_IDCommande = (int)objlsttab[0][1];
           objfacture.m_DateCreation = DateTime.Parse(objlsttab[0][2].ToString());
           objfacture.m_DatePaiementComplet = DateTime.Parse(objlsttab[0][3].ToString());
           objfacture.m_Commentaire = objlsttab[0][4].ToString();
           return objfacture;
       }

       public  static void SupprimerFactureParID(int pID)
       {
           if (pID != -1)
               throw new ArgumentOutOfRangeException("ID non valide");//autre exception?
          Utilitaires.Commandehelper.RequeteSQL("DELETE from facture where ID = " + pID + ";");
          //MessageBox.Show("Petit produit " + pID + " Tu viens de te faire TROLOLOLOL !!!");
           
           
       }

       public void Supprimer()
       {
           Utilitaires.Commandehelper.RequeteSQL("DELETE from facture where ID = " + this.ID + ";");
          
       }

       
       ///static
       ///rechercher par ID
       ///rechercher par Client
       ///supprimer par ID
       ///
       ///dynamique
       ///Payer 
       ///supprimer
       ///
       ///Propriété calculé
       ///prix total
       ///prix initial
       ///



       #endregion
   }
}
